home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11338 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  62 lines

  1. Path: solon.com!not-for-mail
  2. From: R.Ghosh-Roy@brunel.ac.uk (R Ghosh-Roy)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Multiple Indirection (Pointer Arithmatic)
  5. Date: 23 Mar 1996 00:43:28 -0600
  6. Organization: Brunel University, Uxbridge, UK
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4j06ig$7q8@solutions.solon.com>
  10. Reply-To: R.Ghosh-Roy@brunel.ac.uk
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13.  
  14. I am a bit confused about "pointer arithmatic" and therefore would appreciate
  15. your expert help. The following is the problem:
  16.  
  17. I have three arrays (A,B,C) of structures and each structure has its own set
  18. of fields. In structure A, one particular field Ab points to structure B. B
  19. has a field Bc which points to C and C has a field named Cd. I need to look
  20. for Cd for each A. Can I use some kind of clever pointer arithmatic to get
  21. to Cd for each A? Or, is there a cleverer way?
  22.  
  23. Note: 3 arrays of structures A,B and C and only one field relates elements
  24.       of each array, ie, Ab relates to an element within an array of Bs and
  25.       Bc relates to an element within an array of Cs. These are dynamically
  26.       assigned.
  27.  
  28. struct A
  29. |--------|
  30. |        |
  31. |        |
  32. |        |
  33. |        |        struct B
  34. | Ab  ---|------->|--------|
  35. |        |        |        |
  36. |--------|        |        |
  37.                   |        |
  38.                   |        |
  39.                   |        |         struct C
  40.                   | Bc  ---|-------->|----------|
  41.                   |        |         |          |
  42.                   |        |         |          |
  43.                   |        |         |          |
  44.                   |--------|         |          |
  45.                                      |          |
  46.                                      |  Cd      |
  47.                                      |          |
  48.                                      |          |
  49.                                      |          |
  50.                                      |          |
  51.                                      |----------|
  52.  
  53. I was thinking of using sizeof and offsetof expressions. 
  54.  
  55. Thanks,
  56.  
  57. Rana
  58.  
  59.  
  60. -- 
  61. R. Ghosh-Roy @ BIPS  -- R.Ghosh-Roy@brunel.ac.uk -- Extension 2772
  62.